<%--
  Created by IntelliJ IDEA.
  User: 19416
  Date: 2022-11-14
  Time: 20:09
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath }/statics/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${pageContext.request.contextPath }/statics/component/pear/css/pear.css" />
    <link rel="stylesheet" href="${pageContext.request.contextPath }/statics/admin/css/other/login.css" />
</head>
<body background="${pageContext.request.contextPath }/statics/admin/images/background.svg" style="background-size: cover;">
<form class="layui-form" action="" method="post">
    <div class="layui-form-item">
        <img class="logo" src="${pageContext.request.contextPath }/statics/admin/images/logo.png" />
        <div class="title">Pear Admin</div>
        <div class="desc">
            明 湖 区 最 具 影 响 力 的 设 计 规 范 之 一
        </div>
    </div>
    <div class="layui-form-item">
        <input placeholder="账 户 : admin " name="username" id="username" lay-verify="required" hover class="layui-input"  />
    </div>
    <div class="layui-form-item">
        <input placeholder="密 码 : admin " name="password"  id="password" lay-verify="required" hover class="layui-input"  />
    </div>
    <div class="layui-form-item">
        <input placeholder="验证码 : "  name="code" id="code"  hover  lay-verify="required" class="code layui-input layui-input-inline"  />
        <img src="${pageContext.request.contextPath}/login/getCode" class="codeImage" id="codeImg" onclick="An()" />
    </div>
    <div class="layui-form-item" style="height: 50px">
        <input type="checkbox" name="check"  value="1" title="记住密码" lay-skin="primary" checked>
    </div>
    <div class="layui-form-item">
        <button type="button" class="pear-btn pear-btn-success login" lay-submit lay-filter="login">
            登 入
        </button>
    </div>
<%--    <input type="submit">--%>
</form>
<!-- 资 源 引 入 -->
<script src="${pageContext.request.contextPath}/statics/component/layui/layui.js"></script>
<script src="${pageContext.request.contextPath}/statics/component/pear/pear.js"></script>

<script>
    function getCookie(cookieName){
        var cookieValue="";
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = cookies[i];
                if (cookie.substring(0, cookieName.length + 2).trim() == cookieName.trim() + "=") {
                    cookieValue = cookie.substring(cookieName.length + 2, cookie.length);
                    break;
                }
            }
        }
        return cookieValue;
    }



    layui.use(['jquery','button','popup'], function() {
        var form = layui.form;
        var button = layui.button;
        var popup = layui.popup;
        var $ = layui.jquery;

        if(!$("#check").is('.layui-form-checked')){
            $("#username").val(getCookie('username')); // 读取 cookie);
            $("#password").val(getCookie('password')); // 读取 cookie);
        }

        // 登 录 提 交
        form.on('submit(login)', function(data) {

            $.ajax({
                url:'${pageContext.request.contextPath}/login/login',
                type:"post",
                data:data.field,
                success: function (data) {
                    console.log(data)
                    if (data == "1") {
                        button.load({
                            elem: '.login',
                            time:1500,
                            done:function (){
                                popup.success("登录成功", function () {
                                    console.log('aa')
                                    location.href ="${pageContext.request.contextPath}/index"
                                });
                            }
                        })
                    }else {
                        popup.failure("登录失败", function() {
                            refresh();
                        });
                    }
                }

            })


            /// 验证

            /// 登录

            /// 动画

            return false;
        });


    })
</script>
<script>
    function An() {
        document.getElementById("codeImg").src = "${pageContext.request.contextPath}/login/getCode?time=" + new Date().getTime();
    }
</script>
</body>
</html>
